var vue = new Vue({
    el:"#app",
    data:{
      title:"登录",
      user:{
          account:"",
          password:"",
          code:""
      }
    },
    mounted() {
        document.onkeydown = (e) => {
            if (e.keyCode == 13) {
                this.toLogin();
            }
        }
    },
    created:function (){

    },
    methods:{
        toLogin:function (){
            var that = this;
            var user = that.user;

            if(!user.account){
                alert("请输入账号");
                document.getElementById("account").focus();
                return;
            }

            if(!user.password){
                alert("请输入密码");
                document.getElementById("pwd").focus();
                return;
            }

            if(!user.code){
                alert("请输入验证码");
                document.getElementById("code").focus();
                return;
            }

            axios.post("/logined",user).then(function (res){
                if(res.data == "success"){
                    window.location.href = "/"
                }else if(res.data =="failCode") {
                    alert("验证码有误")
                    document.getElementById("code").value = "";
                    document.getElementById("code").focus();
                    document.getElementById("codeImg").src = "/kaptcha?d=" + new Date();
                }else {
                    alert("账号密码有误")
                    document.getElementById("pwd").value = "";
                    document.getElementById("pwd").focus();
                    document.getElementById("codeImg").src = "/kaptcha?d=" + new Date();
                }
            })
        }
    }
})